package com.yswl.pri;

import android.app.ActivityManager;
import android.content.Context;
import android.os.Build;
import android.support.multidex.MultiDex;

import com.bolex.autoEx.AutoEx;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
import com.tencent.bugly.Bugly;
import com.tencent.smtt.sdk.QbSdk;

import yswl.com.klibrary.MApplication;
import yswl.com.klibrary.util.L;

/**
 * Created by kangpAdministrator on 2018/4/24 0024.
 * Emial kangpeng@yunhetong.net
 */

public class App extends MApplication {
    @Override
    public boolean getDebugSetting() {
        return true;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        initBrower();
        if (L.DEGUG) {
            initBug();
            if (LeakCanary.isInAnalyzerProcess(this)) {
                return;
            }
            refWatcher = installLeakCanary();
        }
        /**
         * bugly
         * TAG=CrashReportInfo
         */
        if (Config.UeserConfig.isAwayFree) {
            Bugly.init(getApplicationContext(), "7bda06b814", L.DEGUG);
        } else {
//试用版无法升级
        }




    }



    RefWatcher refWatcher;

    protected RefWatcher installLeakCanary() {
        return RefWatcher.DISABLED;
    }


    void initBug() {
        /**
         * @param mApp    Applicatin
         * @param maxSize 最大提示答案数目
         * @param tag     自定义日志 默认 AutoEx
         * @param isDebug 是否开启调试 true为开启 false为关闭 默认开启
         */
        AutoEx.apply(this, 5, "App", true);

    }


    void initBrower() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
                    @Override
                    public void onViewInitFinished(boolean arg0) {
                        //x5內核初始化完成的回调，为true表示x5内核加载成功，否则表示x5内核加载失败，会自动切换到系统内核。
                        L.d("App", " x5内核初始化完成onViewInitFinished is " + arg0);
                    }

                    @Override
                    public void onCoreInitFinished() {
                        L.d("App", " x5内核初始化失败");
                    }
                };
                //x5内核初始化接口
                QbSdk.initX5Environment(getApplicationContext(), cb);
            }
        }).start();

    }

    /**
     * @return 可以为空，但是需要传入的url全路径即可
     */
    @Override
    public String getBaseUrl_Https() {
        return "";
    }


    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}
